//
//  KAERecordManager.m
//  StudyDemo
//
//  Created by 陶涛 on 2018/8/22.
//  Copyright © 2018年 陶涛. All rights reserved.
//

#import "KAERecordManager.h"

@implementation KAERecordManager

- (instancetype)init
{
    self = [super init];
    if (self) {
        void (^deviceConnectedBlock)(NSNotification *) = ^(NSNotification *notification) {
            AVCaptureDevice *device = [notification object];
            BOOL sessionHasDeviceWithMatchingMediaType = NO;
            NSString *deviceMediaType = nil;
            if ([device hasMediaType:AVMediaTypeAudio]) {
                deviceMediaType = AVMediaTypeAudio;
            } else if ([device hasMediaType:AVMediaTypeVideo]) {
                deviceMediaType = AVMediaTypeVideo;
            }
            if (deviceMediaType) {
                for (AVCaptureDeviceInput *input in [self.session inputs]) {
                    if ([input.device hasMediaType:deviceMediaType]) {
                        sessionHasDeviceWithMatchingMediaType = YES;
                        break;
                    }
                }
                if (!sessionHasDeviceWithMatchingMediaType) {
                    NSError *error;
                    AVCaptureDeviceInput *input = [AVCaptureDeviceInput deviceInputWithDevice:device error:&error];
                    if ([self.session canAddInput:input]) {
                        [self.session addInput:input];
                    }
                }
            }
            if ([self.delegate respondsToSelector:@selector(recordMangerDeviceConfigurationChanged:)]) {
                [self.delegate recordMangerDeviceConfigurationChanged:self];
            }
        };
        
        
    }
    return self;
}

@end
